504225544 by Unknown

504225544 by Unknown

Author:Unknown
Language: eng
Format: epub


The function calculate_age is called once; it returns the calculated age, and this (returned) value is saved in the variable called

This variable my_age is then printed in the Output

Now that you have written the code for your new function, please do the following:

Save your code.

Check that there are no errors in the Output window and play the scene.

The console should display, amongst other things, the message “Your age is

As you can see, there are different types of methods that you can create, depending on your needs. They may or may not take parameters, and they may or may not return values.

Note that we could have specified the type of the data to be returned by the function by modifying its definition as follows (new cold in bold):

func calculate_age(YOB:int)->int:

var age:int = 2021-YOB

return (age)

We could also have specified a default value for the parameter DOB as follows (new cold in bold):

func calculate_age(YOB:int = 2000)->int:

var age:int = 2021-YOB

return (age)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.